'use strict';
	angular.module('inventory.itemBatchSelectSingle', [])
	.controller('itemBatchSelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , f])//控制器结束
    function f($rootScope, $scope, BizData, $uibModalInstance, params, title) {


		var Model = this;
		
		Model.gridRowClick = function(event){
			
		}

		Model.gridRowDblClick = function(event){
			Model.ok();
		}
		
		
		var options = {};
		options.container = Model;
		options.concept = 'ItemBatch';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '/inventory/itemBatch/list/create';
		options.reader = '/inventory/itemBatch/list/query';
		options.writer = '/inventory/itemBatch/list/save';
		options.deleter = '/inventory/itemBatch/list/delete';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.defCols = {fID:{name:"fID",type:"String",label:""},systemCode:{name:"systemCode",type:"String",label:""},billType:{name:"billType",type:"String",label:""},billTypeName:{name:"billTypeName",type:"String",label:""},orderDate:{name:"orderDate",type:"Date",label:""},state:{name:"state",type:"String",label:""},status:{name:"status",type:"String",label:""},itemID:{name:"itemID",type:"String",label:""},itemNo:{name:"itemNo",type:"String",label:""},itemName:{name:"itemName",type:"String",label:""},itemProperty:{name:"itemProperty",type:"String",label:""},itemDescribe:{name:"itemDescribe",type:"String",label:""},unitCode:{name:"unitCode",type:"String",label:""},unitName:{name:"unitName",type:"String",label:""},batchNo:{name:"batchNo",type:"String",label:""},batchDescribe:{name:"batchDescribe",type:"String",label:""},qualityPeriod:{name:"qualityPeriod",type:"Integer",label:""},validDays:{name:"validDays",type:"Integer",label:""},checkoutAgainDays:{name:"checkoutAgainDays",type:"Integer",label:""},qualityType:{name:"qualityType",type:"Integer",label:""},qualityTypeLabel:{name:"qualityTypeLabel",type:"String",label:""},process:{name:"process",type:"String",label:""},processLabel:{name:"processLabel",type:"String",label:""},storeNo:{name:"storeNo",type:"String",label:""},produceDate:{name:"produceDate",type:"Date",label:""},validDate:{name:"validDate",type:"Date",label:""},checkoutAgainDate:{name:"checkoutAgainDate",type:"Date",label:""},firstStoreDate:{name:"firstStoreDate",type:"Date",label:""},lastCheckDate:{name:"lastCheckDate",type:"Date",label:""},brand:{name:"brand",type:"String",label:""},brandLabel:{name:"brandLabel",type:"String",label:""},placeOrigin:{name:"placeOrigin",type:"String",label:""},manufacturer:{name:"manufacturer",type:"String",label:""},providerID:{name:"providerID",type:"String",label:""},storageTypeD:{name:"storageTypeD",type:"String",label:""},storageTypeDLabel:{name:"storageTypeDLabel",type:"String",label:""},providerNo:{name:"providerNo",type:"String",label:""},shortName:{name:"shortName",type:"String",label:""},providerName:{name:"providerName",type:"String",label:""},origin:{name:"origin",type:"String",label:""},originName:{name:"originName",type:"String",label:""},originNo:{name:"originNo",type:"String",label:""},originSerialNo:{name:"originSerialNo",type:"String",label:""},quantityL:{name:"quantityL",type:"Decimal",label:""},pieceQuantityL:{name:"pieceQuantityL",type:"Decimal",label:""},lockFlag:{name:"lockFlag",type:"String",label:""},comments:{name:"comments",type:"String",label:""},cUsercode:{name:"cUsercode",type:"String",label:""},cUsername:{name:"cUsername",type:"String",label:""},cDatetime:{name:"cDatetime",type:"Datetime",label:""},tUsercode:{name:"tUsercode",type:"String",label:""},tUsername:{name:"tUsername",type:"String",label:""},tDatetime:{name:"tDatetime",type:"Datetime",label:""},eUsercode:{name:"eUsercode",type:"String",label:""},eUsername:{name:"eUsername",type:"String",label:""},eDatetime:{name:"eDatetime",type:"Datetime",label:""},userId:{name:"userId",type:"String",label:""},enterpriseNo:{name:"enterpriseNo",type:"String",label:""},enterpriseName:{name:"enterpriseName",type:"String",label:""},version:{name:"version",type:"Integer",label:""}};
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.pathRelation = 'fID';
		options.directDeleteMode = true;
		options.limit = 10;
		options.orderBy = 'batchNo ASC'
		
		$scope.dataList = new BizData(options);

		//监视对象中的所有变动
		$scope.dataList.deregRows = $scope.$watch('dataList.rows',$scope.dataList.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
        	Model.title = title;  
        	Model.params = params;  

    		//设置过滤条件
    		$scope.dataList.filter = "ItemBatch.enterpriseNo like '%"+ Model.params.id +"%'"
    		 + " AND ItemBatch.status='open'"
    		 + " AND ItemBatch.itemID='" + Model.params.itemID + "'"
    		 ;

    		//刷新数据
    	    $scope.dataList.refreshData();
        });  
		
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
	    	var event = {};
	    	var data = [];
	    	var sourceRow = $scope.dataList.rows[$scope.dataList.currentIndex];
	    	var row = {};
			//循环行中的列，取出列的值，装配成简单的行
			for(var obj in sourceRow){
				if(obj!='$$hashKey' && obj!='userdata'){
					row[obj] = sourceRow[obj].value;
				}
			}
	    	data.push(row);
	    	event.data = data;
			$uibModalInstance.close(event);  
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////
	    



	    return Model;
	    
	}	
	
